Rendering
Renderers turn nodes into the Markdown of a flavour (material, the default, or
github). See Markdown flavours for what changes
between them.
import mknodes as mk
from mknodes import rendering
node = mk.MkAdmonition("Careful!", typ="warning")
await node.to_markdown(flavor="github") # > [!WARNING] ...
with rendering.use(rendering.get_renderer("github")):
str(node) # nested nodes, templates and str() render in that flavour
mknodes.rendering.get_renderer
¶
Return a renderer for given flavour name (None: the active renderer).
mknodes.rendering.use
¶
Make given renderer the active one inside the context.
mknodes.rendering.Renderer
¶
Renders nodes as Markdown of one flavour.
Subclass it for a new flavour and register rules with the rule decorator.
Rule lookup walks the node class hierarchy: a rule for MkBlock also renders
MkDetailsBlock, unless a class in between renders itself (defines
get_content / to_md_unprocessed) and has no rule of its own.
Rules of parent renderer classes are inherited.
template_key
class-attribute
¶
[output.<key>] section of node files whose template serves as a rule.
finalize
¶
finalize(output: BuildOutput, root: MkNav) -> None
Post-process a whole build (all pages rendered), in place. Default: nothing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
BuildOutput
|
The build output |
required |
root
|
MkNav
|
The root nav of the build |
required |
find_rule
classmethod
¶
Return the rule for given node type (None: the node renders itself).
process
¶
process(node: MkNode, text: str) -> str
Run the text processors of given node on given text.
processors
¶
processors(node: MkNode) -> list[TextProcessor]
Return the text processors to run on the Markdown of given node.
render
async
¶
render(node: MkNode) -> NodeContent
Render given node (unprocessed Markdown) and collect its resources.
render_child
async
¶
render_child(node: MkNode) -> NodeContent
Render a child node: content with the node's processors applied.
render_children
async
¶
render_children(nodes: list[MkNode], separator: str = '\n\n') -> str
Render given nodes as children and join their Markdown.
render_markdown
async
¶
render_markdown(node: MkNode) -> str
Render the unprocessed Markdown of given node.
rule
classmethod
¶
Decorator registering a render function for given node types.
supports
classmethod
¶
Return whether this renderer has an own rule for given node type.
to_html
¶
Convert Markdown of this flavour to HTML (with a parser knowing the flavour).
The default uses Python-Markdown with the Markdown extensions of given resources
(Material flavour). See mknodes.rendering.html.
mknodes.rendering.MaterialRenderer
¶
mknodes.rendering.github.GithubRenderer
¶
Bases: Renderer
Renders GitHub flavoured Markdown (READMEs, issues, wikis).
finalize
¶
finalize(output: BuildOutput, root: MkNav) -> None
Link [title][dotted.path] references (GitHub has no autorefs).
mknodes.rendering.myst.MystRenderer
¶
Bases: GithubRenderer
Renders MyST Markdown for Sphinx (myst-parser + sphinx-design).
finalize
¶
finalize(output: BuildOutput, root: MkNav) -> None
Link [title][dotted.path] references, add MyST targets for the anchors.
Page info
Code for this page
| mknodes.manual.api_section._add_page.<locals>._ | |
|---|---|